package itsm.isperp.module.service.app;

import itsm.isperp.framework.service.BaseService;
import itsm.isperp.framework.utils.HibernateUUIDGenerator;
import itsm.isperp.module.entity.app.AppPortalPersonConfig;
import itsm.isperp.module.repository.app.AppPortalPersonConfigMapper;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

/**
 * @date 2014-2-24
 * @author Lizx
 */
@Service
public class AppPortalPersonConfigService extends
		BaseService<AppPortalPersonConfig> {

	@Resource
	protected AppPortalPersonConfigMapper appPortalPersonConfigMapper;

	@Override
	public AppPortalPersonConfigMapper getRepository() {
		return this.appPortalPersonConfigMapper;
	}

	public void savePersonPortalConfig(String username, String[] portalIds,
			String[] orderNums) {
		this.getRepository().deleteByUsername(username);

		AppPortalPersonConfig[] arr = new AppPortalPersonConfig[portalIds.length];
		for (int i = 0; i < arr.length; i++) {
			AppPortalPersonConfig item = new AppPortalPersonConfig();
			item.setId(HibernateUUIDGenerator.generate());
			item.setAppPortalId(portalIds[i]);
			item.setAppUserName(username);
			item.setOrderNum(Integer.valueOf(orderNums[i]));
			arr[i] = item;
		}

		this.getRepository().saveBatch(username, arr);

	}
}
